#include<bits/stdc++.h>
using namespace std;
#define int long long

int weight[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char mp[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

signed main() {
	int n;
	cin >> n;

	bool flag = 0;
	while (n--) {
		string s;
		cin >> s;

		bool fg = 0;
		int sum = 0;
		for (int i = 0; i < s.size() - 1; i++) {
			if (!isdigit(s[i])) {
				flag = fg = 1;
				cout << s << endl;
				break;
			}
			sum += (s[i] - '0') * weight[i];
		}
		if (!fg && mp[sum % 11] != s[17]) {
			flag = 1;
			cout << s << endl;
		}
	}
	if (!flag)
		cout << "All passed";
	return 0;
}
